xsplice: Implement support for applying/reverting/replacing patches.
authorRoss Lagerwall <ross.lagerwall@citrix.com>
Wed, 27 Apr 2016 13:07:04 +0000 (09:07 -0400)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 29 Apr 2016 07:58:28 +0000 (03:58 -0400)
commit29f4ab0b0a4ff62589af35b7cbc2334e1d9acdcd
treea5fbc1d7de920ab82e879a70343e6012ace1ec27
parent380b229634f8e27c1abca05e2a8a54b08ca914c5
xsplice: Implement support for applying/reverting/replacing patches.

Implement support for the apply, revert and replace actions.

To perform and action on a payload, the hypercall sets up a data
structure to schedule the work.  A hook is added in the reset_stack_and_jump
to check for work and execute it if needed (specifically we check an
per-cpu flag to make this as quick as possible).

In this way, patches can be applied with all CPUs idle and without
stacks.  The first CPU to run check_for_xsplice_work() becomes the
master and triggers a reschedule softirq to trigger all the other CPUs
to enter check_for_xsplice_work() with no stack.  Once all CPUs
have rendezvoused, all CPUs disable their IRQs and NMIs are ignored.
The system is then quiscient and the master performs the action.
After this, all CPUs enable IRQs and NMIs are re-enabled.

Note that it is unsafe to patch do_nmi and the xSplice internal functions.
Patching functions on NMI/MCE path is liable to end in disaster on x86.
This is not addressed in this patch and is mentioned in the
design doc as a further TODO.

The action to perform is one of:
- APPLY: For each function in the module, store the first arch-specific
  number bytes of the old function and replace it with a jump to the
  new function. (on x86 it is 5 bytes, on ARM it will likey be 4 bytes).
- REVERT: Copy the previously stored bytes into the first arch-specific
  number of bytes of the old function (again, 5 bytes on x86).
- REPLACE: Revert each applied module and then apply the new module.

To prevent a deadlock with any other barrier in the system, the master
will wait for up to 30ms before timing out.
Measurements found that the patch application to take about 100 μs on a
72 CPU system, whether idle or fully loaded.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
xen/arch/arm/xsplice.c
xen/arch/x86/domain.c
xen/arch/x86/xsplice.c
xen/common/xsplice.c
xen/include/asm-x86/current.h
xen/include/public/sysctl.h
xen/include/xen/xsplice.h